package com.study.interface_demo3;

import java.util.ArrayList;

public class ClassDataImpl2 implements ClassData{
    private ArrayList<Student> students;
    public ClassDataImpl2(ArrayList<Student> students) {
        this.students=students;
    }
    @Override
    public void printAllStudentsInfo() {
        int num_male = 0;
        int num_female = 0;
        for (int i = 0; i < students.size(); i++) {
            Student student = students.get(i);
            if(student.getSex()=='男'){
                num_male++;
            }else{
                num_female++;
            }
            System.out.println(student.getName()+" "+student.getSex()+" " + student.getScore());
        }
        System.out.println("男人有"+num_male+"人，女人有"+num_female+"人");
    }

    @Override
    public void printAllStudentsAverageScore() {
        double sumScore = 0;
        double maxScore = students.get(0).getScore();
        double minScore = students.get(0).getScore();
        for (int i = 0; i < students.size(); i++) {
            Student student = students.get(i);
            sumScore+=student.getScore();
            if(student.getScore()>maxScore){
                maxScore=student.getScore();
            }
            if(student.getScore()<minScore){
                minScore=student.getScore();
            }
        }
        System.out.println("平均分："+sumScore/ students.size());
        System.out.println("最高分是："+maxScore+"分，最低分是："+minScore+"分");
    }
}
